<!--
    Copyright 2010 Google Inc.

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.
-->

<html>
<head>
<style>
body {
  min-width:400px;
  min-height:400px;
}

#map_canvas {
  width:100%;
  height:100%;
}
</style>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript">

  function initialize() {
    // Set up the map
    var myOptions = {
      zoom: 12,
      mapTypeId: google.maps.MapTypeId.SATELLITE
    };
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    // Get initial coordinates
    var backgroundPage = chrome.extension.getBackgroundPage();
    setUserPosition(backgroundPage.lat, backgroundPage.long);

    // Inject content script into the current tab
    chrome.tabs.getSelected(null, function(tab) {
      if (tab.url.indexOf('http:') == 0 ||
          tab.url.indexOf('https:') == 0) {
        chrome.tabs.executeScript(null, {file: "content_script.js"});
      }
    });
  }

  function setUserPosition(lat, long) {
    var position = new google.maps.LatLng(lat, long);
    map.setCenter(position);
    addMarker(lat, long, "Your current location"); 
  }

  function addMarker(lat, long, title) {
    var position = new google.maps.LatLng(lat, long);
    var marker = new google.maps.Marker({
        map: map,
        position: position,
        title: title
    });
    var currentBounds = map.getBounds();
    if (currentBounds != null && !currentBounds.contains(position)) {
        currentBounds.extend(position);
        map.fitBounds(currentBounds);
    }
  }
</script>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
</body>
</html>